package com.hejing.object类.Object类之toString方法;

import java.util.Objects;

/**
 * ClassName: Circle
 * Package: com.hejing.object类.Object类之toString方法
 * Description:
 *
 * @Author: HeJing
 * @Create: 2023-03-27 9:45
 * @Version: 1.0
 */
public class Circle extends GeometricObject{
    private double radius;

    public Circle() {
    }

    public Circle(double radius) {
        this.radius = radius;
    }

    public Circle(String color, double radius) {
        super(color);
        this.radius = radius;
    }

    public double getRadius() {
        return radius;
    }

    public void setRadius(double radius) {
        this.radius = radius;
    }

    // 方式1: 手动重写equals()方法
    /*public boolean equals(Object obj) {
        if(this == obj) return true;
        if(obj == null || getClass() != obj.getClass()) return false;
        Circle circle = (Circle)obj;
        return circle.getRadius() == radius;
    }*/

    // IDEA 自动生成equals()方法

    @Override
    public boolean equals(Object o) {
        if (this == o) return true;
        if (o == null || getClass() != o.getClass()) return false;
        Circle circle = (Circle) o;
        return Double.compare(circle.radius, radius) == 0;
    }

    @Override
    public int hashCode() {
        return Objects.hash(radius);
    }

    // 手动重写  toString()方法
 /*   public String toString() {
        return "Circle { 'radius': " + radius + " }";
    }*/

    // 方式2: IDEA自动生成toString()方法


    @Override
    public String toString() {
        return "Circle{" +
                "radius=" + radius +
                '}';
    }
}

















